//
//  BaseSearchController.m
//  Rail
//
//  Created by hychen on 2018/3/4.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "BaseSearchController.h"

@interface BaseSearchController ()

@end

@implementation BaseSearchController

- (void)viewDidLoad {
    [super viewDidLoad];
    //如果进入预编辑状态,searchBar消失(UISearchController套到TabBarController可能会出现这个情况),请添加下边这句话
    self.definesPresentationContext = YES;
    self.searchResultVC.searchBar = self.searchController.searchBar;
//    self.searchResultVC.dataArray = self.dataArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(instancetype)initWithResultController:(BaseSearchResultController *)resultController{
    self = [super init];
    if (self) {
        self.searchResultVC = resultController;
    }
    return self;
}

- (UISearchController *)searchController{
    
    if (!_searchController) {
        //创建UISearchController
        _searchController = [[UISearchController alloc]initWithSearchResultsController:self.searchResultVC];
        //        _searchController.delegate = self;
        //        _searchController.searchResultsUpdater = self.searchResultVC;
        //        _searchController.searchBar.delegate = self;
        
        [_searchController.searchBar sizeToFit];
        _searchController.searchBar.placeholder = @"搜索";
        //        _searchController.searchBar.text = @"默认搜索内容";
        
        //包着搜索框外层的颜色
        _searchController.searchBar.tintColor = kWhiteColor;
        _searchController.searchBar.barTintColor = Color_NavBgColor;
        _searchController.searchBar.backgroundColor = Color_NavBgColor;
        //        _searchController.searchBar.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
        
        //设置UISearchController的显示属性，以下3个属性默认为YES
        //搜索时，背景变暗色
        _searchController.dimsBackgroundDuringPresentation = NO;
        //        _searchController.obscuresBackgroundDuringPresentation = NO;
        //        //点击搜索的时候,是否隐藏导航栏
        //        _searchController.hidesNavigationBarDuringPresentation = NO;
        
    }
    return _searchController;
}

- (void)setSearchPlaceholder:(NSString *)placeholder {
    _searchController.searchBar.placeholder = placeholder;
}

- (void)setSearchBackgroundColor:(UIColor *)color {
    _searchController.searchBar.tintColor = color;
}
@end
